package org.wendu.wdoa.api;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.wendu.wdoa.common.CurrentUser;
import org.wendu.wdoa.common.Result;
import org.wendu.wdoa.common.page.Page;
import org.wendu.wdoa.dto.TaskBeanDto;
import org.wendu.wdoa.dto.TaskDto;
import org.wendu.wdoa.model.Task;
import org.wendu.wdoa.service.TaskService;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/task/newassi")
public class TaskController {

    @Autowired
    private TaskService taskService;


    //新建任务 任务状态为0
    @PostMapping("")
    public Result newTask(@AuthenticationPrincipal CurrentUser currentUser, @RequestBody TaskDto taskDto){
        log.debug("领导I:{}",currentUser.getUserId());
        taskService.addNewTask(currentUser,taskDto);

        return Result.OK("新增任务成功");
    }

    //保存任务 任务状态设置为1
    @PutMapping("/hold/{task_id}")  //传来task_title
    public Result holdTask(@PathVariable String task_id){
        //通过主键id来保存任务
        taskService.holdNewTask(task_id);
        return Result.OK("提交任务成功!");
    }

    //查询任务列表
    @GetMapping("/select")
    public Result<List<Task>> selectTask(@AuthenticationPrincipal CurrentUser currentUser){
        List<Task> page = taskService.selectAllTask(currentUser);
        return Result.OK(page);
    }

    //查询未确定任务列表
    @GetMapping("/selectNo")
    public Result<List<Task>> selectTaskNo(@AuthenticationPrincipal CurrentUser currentUser){
        List<Task> page = taskService.selectNoTask(currentUser);
        return Result.OK(page);
    }

    //修改任务内容
    @PutMapping("/modify")
    public Result modifyTask(@RequestBody TaskDto taskDto){
        taskService.modifyTask(taskDto);
        return Result.OK();
    }

    //删除任务
    @DeleteMapping("/delete/{task_id}")
    public Result deleteTaskOne(@PathVariable String task_id){
        taskService.deleteTaskOne(task_id);
        return Result.OK("删除任务成功!");
    }

    //发布任务 对t_task_rec进行操作,前端传来TasDto（包含任务表主键，创建任务的时间），分派给哪个员工的任务
    @PostMapping("/issue")
    public Result issueTask(@RequestBody TaskBeanDto taskBeanDto){
        log.debug("taskBean.e_id:{}",taskBeanDto.getE_id());
        taskService.issueTask(taskBeanDto);
        return Result.OK("发布成功!");
    }

    //查询当前领导所在部门的员工   目的：选择发布任务 员工的复选框

}
